package com.zhuannimei.parser;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.lidroid.xutils.util.LogUtils;
import com.zhuannimei.domain.JoinPeople;
import com.zhuannimei.utility.WuLog;

/**
 * 参与者列表解析器
 * 
 * @author JackWu
 * 
 */
public class JoinListParser extends BaseJSONParser<List<JoinPeople>> {
	
	private static final String TAG = "JoinListParser";

	@Override
	public List<JoinPeople> parseJSON(String jsonstr) throws JSONException {
		JSONObject jo = new JSONObject(jsonstr);
		JSONArray jsonArray = jo.getJSONArray("result");
		List<JoinPeople> mlist = new ArrayList<JoinPeople>();
		for (int i = 0; i < jsonArray.length(); i++) {
			JSONObject obj = jsonArray.getJSONObject(i);
			JoinPeople jp = new JoinPeople();
			jp.setUserName(obj.optString("username"));
			jp.setCrtime(obj.optString("ctime"));
			jp.setUserId(obj.optString("userId"));
			jp.setNumber(obj.optString("number"));
			JSONArray codes = obj.getJSONArray("codes");
			StringBuffer sb = new StringBuffer();
			for(int x=0;x<codes.length();x++){
				String code = codes.getString(x);
				sb.append(code);
				if(x!=codes.length()-1){
					sb.append(",");
				}
			}
			jp.setCodes(sb.toString());
			WuLog.i(TAG, "" + sb.toString());
			mlist.add(jp);
		}
		return mlist;
	}

}
